import axios from 'axios'
import Vue from 'vue'
import { Toast } from 'vant'
Vue.use(Toast)
// import { Message, Loading } from 'element-ui'
const ConfigBaseURL = 'http://124.222.249.103:3000'
let loadingInstance = null
export const Service = axios.create({
  timeout: 7000, // 请求超时时间
  baseURL: ConfigBaseURL,
  method: 'post',
  headers: {
    'Content-Type': 'application/json;charset=UTF-8'
  }
})
// 添加请求拦截器
Service.interceptors.request.use(config => {
  console.log('我进来了')
  // loadingInstance = Loading.service({
  //   lock: true,
  //   text: 'loading...'
  // })
  return config
})
// 添加响应拦截器
Service.interceptors.response.use(response => {
  // loadingInstance.close()
  // console.log(response)
  return response.data
}, error => {
  console.log('TCL: error', error)
  const msg = error.Message !== undefined ? error.Message : ''
  Toast.fail('请求错误');
  // Message({
  //   message: '网络错误' + msg,
  //   type: 'error',
  //   duration: 3 * 1000
  // })
  // loadingInstance.close()
  return Promise.reject(error)
})
